#include<stdio.h>

int binarySearch(int[], int, int, int);

int main(int argc, char* argv[]) {
  int array[5] = { 1, 3, 5, 8, 10 };
  printf("Index: %d\n", binarySearch(array, 10, 0, 4));
  return 0;
}

int binarySearch(int array[], int value, int left, int right) {
  while (left <= right) {
    int middle = (left + right) / 2;
    if (array[middle] == value)
      return middle;
    else if (array[middle] < value)
      left = middle + 1;
    else
      right = middle - 1;
  }
  return -1;
}
